package com.classify.system.domain;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.shopgoods.common.core.annotation.Excel;
import com.shopgoods.common.core.web.domain.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
 * 商品分类对象 sg_classify
 *
 * @author shopgoods
 * @date 2024-11-14
 */
public class SgClassifyPO extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /** 分类ID */
    private Integer classifyId;

    /** 分类名称 */
    @Excel(name = "分类名称")
    private String classifyName;

    /** 上级分类ID */
    @Excel(name = "上级分类ID")
    private Integer parentCategoryId;

    /** 数量单位 */
    @Excel(name = "数量单位")
    private String quantityUnit;



    /** 排序 */
    @Excel(name = "排序")
    private Integer sortOrder;

    /** 是否显示 */
    @Excel(name = "是否显示")
    private Integer isDisplayed;

    /** 是否显示在导航栏 */
    @Excel(name = "是否显示在导航栏")
    private Integer isInNavbar;

    /** 分类图标 */
    @Excel(name = "分类图标")
    private String categoryIcon;

    /** 筛选属性 */
    @Excel(name = "筛选属性")
    @JsonDeserialize(using = CommaSeparatedListDeserializer.class)
//    @JsonProperty("filterAttributes")
    private List<String> filterAttributes;

    /** 关键词 */
    @Excel(name = "关键词")
    private String keywords;

    /** 分类描述 */
    @Excel(name = "分类描述")
    private String description;

    /** 创建时间 */
    private Date createdAt;

    /** 更新时间 */
    private Date updatedAt;

    /** 父级编号 */
    private Integer pid;


    /** 子集合 */
    private List<SgClassifyPO> children;

    public List<SgClassifyPO> getChildren() {
        return children;
    }

    public void setChildren(List<SgClassifyPO> children) {
        this.children = children;
    }

    public void setClassifyId(Integer classifyId)
    {
        this.classifyId = classifyId;
    }

    public Integer getClassifyId()
    {
        return classifyId;
    }
    public void setClassifyName(String classifyName)
    {
        this.classifyName = classifyName;
    }

    public Integer getPid() {
        return pid;
    }

    public void setPid(Integer pid) {
        this.pid = pid;
    }

    public String getClassifyName()
    {
        return classifyName;
    }
    public void setParentCategoryId(Integer parentCategoryId)
    {
        this.parentCategoryId = parentCategoryId;
    }

    public Integer getParentCategoryId()
    {
        return parentCategoryId;
    }
    public void setQuantityUnit(String quantityUnit)
    {
        this.quantityUnit = quantityUnit;
    }

    public String getQuantityUnit()
    {
        return quantityUnit;
    }
    public void setSortOrder(Integer sortOrder)
    {
        this.sortOrder = sortOrder;
    }

    public Integer getSortOrder()
    {
        return sortOrder;
    }
    public void setIsDisplayed(Integer isDisplayed)
    {
        this.isDisplayed = isDisplayed;
    }

    public Integer getIsDisplayed()
    {
        return isDisplayed;
    }
    public void setIsInNavbar(Integer isInNavbar)
    {
        this.isInNavbar = isInNavbar;
    }

    public Integer getIsInNavbar()
    {
        return isInNavbar;
    }
    public void setCategoryIcon(String categoryIcon)
    {
        this.categoryIcon = categoryIcon;
    }

    public String getCategoryIcon()
    {
        return categoryIcon;
    }

    public void setKeywords(String keywords)
    {
        this.keywords = keywords;
    }

    public String getKeywords()
    {
        return keywords;
    }
    public void setDescription(String description)
    {
        this.description = description;
    }

    public String getDescription()
    {
        return description;
    }
    public void setCreatedAt(Date createdAt)
    {
        this.createdAt = createdAt;
    }

    public Date getCreatedAt()
    {
        return createdAt;
    }
    public void setUpdatedAt(Date updatedAt)
    {
        this.updatedAt = updatedAt;
    }

    public Date getUpdatedAt()
    {
        return updatedAt;
    }

    public String getFilterAttributesAsString() {
        return filterAttributes != null ? String.join(",", filterAttributes) : null;
    }

    public void setFilterAttributes(List<String> filterAttributes) {
        this.filterAttributes = filterAttributes;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
            .append("classifyId", getClassifyId())
            .append("classifyName", getClassifyName())
            .append("parentCategoryId", getParentCategoryId())
            .append("quantityUnit", getQuantityUnit())
            .append("sortOrder", getSortOrder())
            .append("isDisplayed", getIsDisplayed())
            .append("isInNavbar", getIsInNavbar())
            .append("categoryIcon", getCategoryIcon())
            .append("filterAttributes", getFilterAttributesAsString())
            .append("keywords", getKeywords())
            .append("description", getDescription())
            .append("createdAt", getCreatedAt())
            .append("updatedAt", getUpdatedAt())
            .append("pid", getPid())
            .append("children", getChildren())
            .toString();
    }

    public class CommaSeparatedListDeserializer extends JsonDeserializer<List<String>> {
        @Override
        public List<String> deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
            String value = p.getText();
            if (value == null) {
                return Collections.emptyList();
            }
            return Arrays.asList(value.split(","));
        }
    }

}
